home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / DocShell / RlShell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  15.7 KB  |  533 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        RlShell.h
  3.  
  4.     Contains:    definition of RealShell class
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <7>     6/21/96    CSL        1341242: Shouldn't be able to activate
  13.                                     windows w/modal dialog up
  14.          <6>     6/20/96    JP        1339269: Made quit handle the saving
  15.                                     parameter too
  16.          <5>     5/31/96    jpa        T10012: OpenFile takes forceOpenApp param,
  17.                                     returns document. Added dreaded Quit
  18.                                     command.
  19.          <4>    .03.1996    NP        1307182: Stuff for caching shell menu
  20.                                     items.
  21.          <3>    .03.1996    NP        1304875,1317218: Fix can't-cancel problem
  22.                                     on receipt of quit event.
  23.          <2>      3/1/96    JP        1314798: Added param to OpenAnotherFile
  24.  
  25.     To Do:
  26.     In Progress:
  27.         
  28. */
  29.  
  30.  
  31. #ifndef _RLSHELL_
  32. #define _RLSHELL_
  33.  
  34. #ifndef _PLFMDEF_
  35. #include "PlfmDef.h"
  36. #endif
  37.  
  38. #ifndef _ODTYPES_
  39. #include <ODTypes.h>
  40. #endif
  41.  
  42. #ifndef SOM_ODDraft_xh
  43. #include <Draft.xh>            /* for ODDraftPermissions */
  44. #endif
  45.  
  46. #ifndef _PLFMFILE_
  47. #include "PlfmFile.h"
  48. #endif
  49.  
  50. #ifndef _LINKLIST_
  51. #include <LinkList.h>
  52. #endif
  53.  
  54. #ifndef __PROCESSES__
  55. #include <Processes.h>        /* For ProcessSerialNumber */
  56. #endif
  57.  
  58. #ifndef __DIALOGS__
  59. #include <Dialogs.h>
  60. #endif
  61.  
  62.  
  63. //==============================================================================
  64. // Theory of Operation
  65. //==============================================================================
  66.  
  67. /*
  68.     The Shell contains all code which interfaces a particular platform's
  69.     user interface with the OpenDoc parts underneath.  
  70.     Each document is run in its own process.
  71.  
  72. */
  73.  
  74. //==============================================================================
  75. // Constants
  76. //==============================================================================
  77.  
  78.  
  79. //-------------------------------------------------------------------------------------
  80. // Menus
  81. //-------------------------------------------------------------------------------------
  82.  
  83. #define    kSHLMenuAbout    1
  84.  
  85. enum {
  86.     kSHLMenuNew            =    1
  87.     ,kSHLMenuOpen
  88.     ,kSHLMenuOpenDocument
  89.     ,kSHLMenuInsert
  90.     ,kSHLMenuClose
  91.     ,kSHLMenuDeleteDocument
  92.  
  93.     // menu separator
  94.  
  95.     ,kSHLMenuSave        =    8
  96.     ,kSHLMenuSaveACopy
  97.     ,kSHLMenuRevert
  98.     ,kSHLMenuDraft
  99.     ,kSHLMenuDocumentInfo
  100.     
  101.     // menu separator
  102.  
  103.     ,kSHLMenuPageSetup    =    14
  104.     ,kSHLMenuPrint
  105.     
  106. #ifdef SUPPORT_QUIT
  107.     // menu separator
  108.     
  109.     ,kSHLMenuQuit        =    17    /* Used only in APPL processes like CyberDog */
  110. #endif
  111. };
  112.  
  113.  
  114. enum {
  115.     kSHLMenuUndo        =    1
  116.     ,kSHLMenuRedo
  117.     
  118.     // menu separator
  119.  
  120.     ,kSHLMenuCut        =    4
  121.     ,kSHLMenuCopy
  122.     ,kSHLMenuPaste
  123.     ,kSHLMenuPasteAs
  124.     ,kSHLMenuClear
  125.     ,kSHLMenuSelectAll
  126.     
  127.     // menu separator
  128.  
  129.     ,kSHLMenuGetPartInfo=    11
  130.     ,kSHLMenuPreferences
  131.  
  132.     // menu separator
  133.  
  134.     ,kSHLMenuViewAsWin    =    14
  135. };
  136.  
  137.  
  138. //-------------------------------------------------------------------------------------
  139. // Dialogs
  140. //-------------------------------------------------------------------------------------
  141.  
  142. const ODSShort    kSHLscOK = 1;                        //OK button
  143. const ODSShort    kSHLscCancel = 2;                    //Cancel button
  144. const ODSShort    kSHLscNo = 3;                        //no, don't save
  145.  
  146. //==============================================================================
  147. // Scalar Types
  148. //==============================================================================
  149.  
  150. typedef    ODSShort    ODResNumber;
  151.  
  152. typedef struct {
  153.     UserItemUPP iconUPP;
  154.     ODBoolean makeStationery;
  155.     ODSession* session;
  156.     ODType changeKind;
  157.     ODType partKind;
  158.     ODTypeList* kindList;
  159. } SaveCopyStruct;
  160.  
  161. //==============================================================================
  162. // Classes defined in this interface
  163. //==============================================================================
  164.  
  165. class RealShell;
  166.  
  167. //==============================================================================
  168. // Classes used by this interface
  169. //==============================================================================
  170.  
  171. class ODSession;
  172. class ODDispatcher;
  173. class ODWindowState;
  174. class ODArbitrator;
  175. class ODDraft;
  176. class ODDocument;
  177. class ODContainer;
  178. class ODMenuBar;
  179. class ShellSI;
  180. class SIHelper;
  181. class PlatformFile;
  182. class StandardFileReply;
  183. class OrderedCollection;
  184. class ODAppleEvent;
  185. class ODDesc;
  186.  
  187. //==============================================================================
  188. // Functions defined in this interface
  189. //==============================================================================
  190.  
  191. void    CreateNewUntitledFile(PlatformFile* newFile); // newFile is in/out
  192.     // Will be moved to DocUtils. - TÇ
  193.  
  194. //==============================================================================
  195. // RealShell
  196. //==============================================================================
  197.  
  198. class RealShell
  199. {    
  200. public:
  201.  
  202. //-------------------------------------------------------------------------------------
  203. // Constructor/Destructor/Initialize/Shutdown/Go
  204. //-------------------------------------------------------------------------------------
  205.  
  206.     RealShell();
  207.     ODNVMethod ~RealShell();
  208.  
  209.     ODNVMethod void Initialize();    
  210.     ODNVMethod void InstallMenuBar();
  211.     ODNVMethod void InstallShellPlugIns(ODDraft* draft);
  212.     ODNVMethod void ScanShellPlugInsFldr(ODSShort fldrVRefNum, ODSLong fldrDirID,
  213.                                         ODDraft* draft);
  214.  
  215.     ODNVMethod void go();
  216.  
  217. //-------------------------------------------------------------------------------------
  218. // public for AppleEvent handlers, but private by convention
  219. //-------------------------------------------------------------------------------------
  220.  
  221.     //-------------------------------------------------------------------------------------
  222.     // Getters/Setters
  223.  
  224.     ODNVMethod ODSession* GetSession()    {return fSession;}    
  225.     ODNVMethod Environment* GetEV()    {return fEV;}    
  226.  
  227.     ODNVMethod void SetAEError(ODError error);
  228.  
  229.     //-------------------------------------------------------------------------------------
  230.     // Close
  231.  
  232.     ODNVMethod void            CloseWindow(ODPlatformWindow window,
  233.                                         DescType saveOptions);
  234.  
  235.     ODNVMethod ODBoolean    CloseDocument(ODDocument* document,
  236.                                             DescType saveOptions);
  237.     
  238.     ODNVMethod void            CloseAllDocs( DescType saveOptions );
  239.  
  240.  
  241.     //-------------------------------------------------------------------------------------
  242.     // Save
  243.  
  244.     ODNVMethod ODBoolean Save(ODDocument* document, 
  245.                                 ODBoolean isClosing = kODFalse, 
  246.                                 ODDescType saveOptions = kAEAsk);
  247.     // if it was a first save, and the user canceled, then it returns kODFalse.
  248.     // The second parameter is needed because if it is a first save in response to the (Save) button from the
  249.     // DontSave/Save/Cancel dialog, and if the user is saving to a different volume, then there is no need to
  250.     // reopen the document after closing and moving it to the new volume.
  251.     // The third parameter is needed because if the user requested that the file be closed and saved,
  252.     // he doesn't want a save dialog to appear
  253.  
  254. protected:
  255.  
  256.  
  257. //-------------------------------------------------------------------------------------
  258. // Event Dispatching
  259. //-------------------------------------------------------------------------------------
  260.     
  261.     ODNVMethod void         DispatchEvent(ODEventData* event);
  262.     ODNVMethod void         DispatchMouseDownEvent(ODEventData* event);
  263.     ODNVMethod void         DispatchMenuEvent(ODEventData* event);
  264.     ODNVMethod void         DispatchKeyDownEvent(ODEventData* event);
  265.     
  266.     ODNVMethod void         HandleOSEvent(ODEventData* event);    
  267.     ODNVMethod void         HandleHighLevelEvent(ODEventData* event);
  268.     
  269.     ODNVMethod void            HandleMenuCommand(ODSLong menuResult, ODEventData* event);
  270.     ODNVMethod void         HandleMouseDownInWindow(WindowPtr window, ODSShort partcode, ODEventData* event);
  271.     ODNVMethod void            HandleMouseDownInCloseBox(WindowPtr window, ODEventData* event);
  272.     ODNVMethod void            HandleMouseDownInDragRegion(WindowPtr window, ODEventData* event);
  273.     ODNVMethod void            HandleMouseDownInGrowBox(WindowPtr window, ODEventData* event);
  274.     ODNVMethod void            HandleMouseDownInZoomBox(WindowPtr window, ODSShort partcode, ODEventData* event);
  275.  
  276.     ODNVMethod void            ExportClipboard(ODBoolean canAlert);
  277.     
  278.     ODNVMethod ODBoolean    CheckFileLocation( );
  279.     ODNVMethod void            NotifyDragToTrash( ODULong );
  280.     ODNVMethod void            CloseTrashedDocument(ODDocument* document, DescType saveOptions );
  281.  
  282.     ODNVMethod ODBoolean    IsSessionModal();
  283.  
  284.     //-------------------------------------------------------------------------
  285.     // Update menus
  286.  
  287.     struct MenuItemInfo
  288.     {
  289.         Str255    text;
  290.         short    cmdChar;
  291.         short    iconID;
  292.         short    markChar;
  293.         Style    textStyle;
  294.     };
  295.  
  296.     ODNVMethod     void    CheckMenuBar();
  297.     ODNVMethod    void    UpdateMenus();
  298.     ODNVMethod    void    UpdateUndoMenus();
  299.     ODNVMethod    void    SaveMenuItem(MenuHandle menu, short itemNum,
  300.                                         MenuItemInfo* info);
  301.     ODNVMethod    void    RestoreMenuItem(MenuHandle menu, short itemNum,
  302.                                         MenuItemInfo* info);
  303.     ODNVMethod     void    ResetUndoText(MenuHandle editMenu);
  304.     ODNVMethod     void    ResetRedoText(MenuHandle editMenu);
  305.  
  306. //-------------------------------------------------------------------------------------
  307. // Memory Management
  308. //-------------------------------------------------------------------------------------
  309.  
  310.     ODNVMethod    void    InitMemory( );    
  311.  
  312.     ODNVMethod    ODSize    Purge(ODSize size);
  313.     
  314.     ODNVMethod    ODSize    IsFreeMemoryLow( ODBoolean &appIsLow, ODBoolean &tempIsLow );
  315.     
  316.     ODNVMethod    ODBoolean    CheckFreeMemory( );        // Returns false if low on memory
  317.     
  318.     ODNVMethod    void    LowMemoryAlert( ODBoolean tempMem );
  319.  
  320. //-------------------------------------------------------------------------------------
  321. // Shell User Functionality
  322. //-------------------------------------------------------------------------------------
  323.  
  324.     //-------------------------------------------------------------------------
  325.     // New (document)
  326.  
  327.     ODNVMethod PlatformFile* New();
  328.         // implements the menu command
  329.         // create a new document with the same part as the root part of the active window
  330.                 
  331.     //-------------------------------------------------------------------------
  332.     // Open (document)
  333.  
  334.     ODNVMethod ODDocument* OpenFile(PlatformFile* file,
  335.                                     ODBoolean forceOpenApp =kODFalse);
  336.     
  337.     ODNVMethod void OpenAnotherFile(PlatformFile* file,
  338.             AEDescList* replyInfo = kODNULL,
  339.             ODBoolean deleteOnFailure = kODFalse,
  340.             ODBoolean unsavedDoc = kODFalse);
  341.  
  342.     ODNVMethod void OpenStdFile();
  343.  
  344.     //-------------------------------------------------------------------------
  345.     // Close (window/document)
  346.  
  347.     ODNVMethod ODBoolean DoesUserCancelClose(ODDocument* document, DescType saveOptions);    
  348.     
  349.     //-------------------------------------------------------------------------
  350.     // Delete (document)
  351.  
  352.     ODNVMethod void DeleteDocument(ODDocument* document);    
  353.  
  354.     //-------------------------------------------------------------------------
  355.     // Save (document)
  356.  
  357.     ODNVMethod void ShowSaveDiffVolDialog( );
  358.     ODNVMethod void CloseSaveDiffVolDialog( );
  359.  
  360.  
  361.     ODNVMethod ODBoolean AskUserWhereToPutIt(
  362.                 ODDraft* whichDraft, Str255 defaultName, 
  363.                 Str255 msg, StandardFileReply* reply );
  364.  
  365.     ODNVMethod void SaveACopy(ODDraft* draft);        
  366.  
  367.     //-------------------------------------------------------------------------
  368.     // Revert (document)
  369.  
  370.     ODNVMethod    void    Revert(ODDocument* document);    
  371.  
  372.     ODNVMethod    ODBoolean    DoesUserOKRevert(ODDocument* document);    
  373.         
  374.     //-------------------------------------------------------------------------
  375.     // Drafts (of document)
  376.  
  377.     ODNVMethod    void        Drafts(ODDocument* document);    
  378.         
  379.     //-------------------------------------------------------------------------
  380.     // Info
  381.  
  382.     ODNVMethod    void        DocumentInfo(ODDocument* document);    
  383. //    ODNVMethod    void        PartInfo();    
  384.  
  385. //-------------------------------------------------------------------------------------
  386. // Error Handling & Notification
  387. //-------------------------------------------------------------------------------------
  388.  
  389.     ODNVMethod    void        ExceptionAlert(ODError exceptionCode, const char message[]);
  390.  
  391.     ODNVMethod    ODBoolean    SearchErrTable(    ODError value,
  392.                                             ODResNumber resourceID,
  393.                                             Str255 str);
  394.  
  395.     ODNVMethod    ODBoolean    LookupErrString(ODError value,
  396.                                                ODResNumber resourceID,
  397.                                                Str255 str);
  398.  
  399.     ODNVMethod    ODError    GetAEError();
  400.     
  401.     
  402.     // Pointer to notifier method which returns void and takes a refCon:
  403.     typedef    void (RealShell::*Notifier) ( ODULong refCon );
  404.     
  405.     ODNVMethod    void    Notify( RealShell::Notifier, ODULong refCon =0 );
  406.     
  407.     ODNVMethod    void    CancelNotification( RealShell::Notifier );
  408.     
  409.     ODNVMethod    void    ShowPendingNotifications( );
  410.  
  411.     ODNVMethod    void    LaunchFailed( ODSLong launchErr,
  412.                                     const ProcessSerialNumber &psn,
  413.                                     Str255 appName, Str255 libName );
  414.  
  415. //-------------------------------------------------------------------------------------
  416. // Apple Event Support
  417. //-------------------------------------------------------------------------------------
  418.  
  419.     ODNVMethod void InitAE();
  420.     
  421.     ODNVMethod void FakePrintMenuEvent();
  422.     
  423.     static pascal ODError HandleOpenAppEvent(ODPart*    thePart,
  424.                                             ODAppleEvent* message,
  425.                                             ODAppleEvent* reply,
  426.                                             ODSLong     refCon);
  427.                             
  428.     static pascal ODError HandleOpenPrintDocsEvent(    ODPart*    thePart,
  429.                                 ODAppleEvent* message,
  430.                                 ODAppleEvent* reply,
  431.                                 ODSLong     refCon);
  432.                                                                                             
  433.     static pascal ODError HandleQuitEvent(    ODPart*    thePart,
  434.                             ODAppleEvent* message,
  435.                             ODAppleEvent* reply,
  436.                             ODSLong     refCon);
  437.                                         
  438.     static pascal ODError HandleLaunchFailedEvent(    ODPart*    thePart,
  439.                             ODAppleEvent* message,
  440.                             ODAppleEvent* reply,
  441.                             ODSLong     refCon);
  442.                                         
  443.     static pascal ODError HandleODActivate( ODPart* thePart, 
  444.                             ODAppleEvent* message,
  445.                             ODAppleEvent* reply,
  446.                             ODSLong handlerRefcon );
  447.         
  448.     static pascal ODError CoerceToFSSpec(ODPart* thePart,
  449.                                 ODDesc* theAEDesc,
  450.                                 DescType toType,
  451.                                 ODSLong handlerRefCon,
  452.                                 ODDesc* result);
  453.  
  454.  
  455. //-------------------------------------------------------------------------------------
  456. // Utilities for setting/getting file names ($opt: can probably inline these)
  457. //-------------------------------------------------------------------------------------
  458.  
  459.     void            GetUserFileName(char* fileName, ODULong maxLen);
  460.  
  461. //-------------------------------------------------------------------------------------
  462. // Utilities to be moved to DocUtils
  463. //-------------------------------------------------------------------------------------
  464.  
  465.     ODNVMethod void CreateUniqueTmpFolderForFile(FSSpec* result,
  466.             Str63 fileName);
  467.  
  468.     ODNVMethod void    CreateUntitledContainer(ODDocument** documentPtr,
  469.             ODContainer** containerPtr, PlatformFile* newFile, ODName* fileNameSeed = kODNULL);
  470.         // *documentPtr, *containerPtr are filled in
  471.         // newFile is in/out
  472.  
  473.     ODNVMethod void    CreateTitledContainer(ODDocument** documentPtr,
  474.             ODContainer** containerPtr, PlatformFile* newFile, char* newName);
  475.         // *documentPtr, *containerPtr are filled in
  476.         // newFile is in/out
  477.  
  478.     ODNVMethod void GetCurrentProcessInfo( ProcessInfoRec *info,
  479.                             StringPtr name =kODNULL, FSSpec *appLoc =kODNULL );
  480.  
  481. //-------------------------------------------------------------------------------------
  482. // private fields
  483. //-------------------------------------------------------------------------------------
  484.  
  485.     //-------------------------------------------------------------
  486.     // session fields
  487.  
  488.     Environment*        fEV;
  489.     ODSession*             fSession;
  490.     ODDispatcher*         fDispatcher;
  491.     ODWindowState*        fWindowState;
  492.     ODArbitrator*        fArbitrator;
  493.     SIHelper*             fSIHelper;
  494.     short                fUniqueNameSeed;
  495.     ODTypeToken         fModalFocusToken;
  496.     
  497.     MenuItemInfo        fDefaultUndoMenuItem;
  498.     MenuItemInfo        fDefaultRedoMenuItem;
  499.     MenuItemInfo        fDefaultAboutMenuItem;
  500.     MenuItemInfo        fDefaultPrefsMenuItem;
  501.     
  502.     ODBoolean            fAPPLProcess;
  503.  
  504.     //-------------------------------------------------------------
  505.     // transitional state fields
  506.  
  507.     ODBoolean            fOptionKeyDownOnMenuBarClick;
  508.     ODBoolean            fShellHasMenuFocus;
  509.     ODBoolean            fAlreadyInCoercion;
  510.     ODError                fErrorFromOpenEvents;
  511.     ODBoolean            fProcessIsActive;
  512.  
  513.     ProcessSerialNumber    fLastNewDocPSN;
  514.     ODFileSpec            fLastNewDocSpec;
  515.     SaveCopyStruct*     fSaveCopyData;
  516.     DialogPtr            fSaveDiffVolDialog;
  517.     
  518.     //-------------------------------------------------------------
  519.     // error/notification fields
  520.  
  521.     ODBoolean            fLowMemNotified;
  522.     
  523.     Str63                fFailedPlugInName;
  524.     
  525.     LinkedList            fNotifiers;
  526.     
  527.     friend struct NotEntry;        // It has a Notifier as a member
  528. };
  529.  
  530.  
  531.  
  532. #endif    // _RLSHELL_
  533.